package com.zc.zby.fwone;

import android.util.Log;


/**
 *   logging system
 */
public final class LogUtil {

    public final static boolean IS_DEBUG = true;
    public final static boolean IS_TEST_SERVER = true;

    private LogUtil() {
    }

    @SuppressWarnings("unused")
    public static int v(String msg) {
        if (IS_DEBUG) {
            return Log.v(getClassName(), msg);
        }
        return 0;
    }

    @SuppressWarnings("unused")
    public static int v(String msg, Throwable tr) {
        if (IS_DEBUG) {
            return Log.v(getClassName(), msg, tr);
        }
        return 0;
    }

    @SuppressWarnings("unused")
    public static int d(String msg) {
        if (IS_DEBUG) {
            return Log.d(getClassName(), msg);
        }
        return 0;
    }

    @SuppressWarnings("unused")
    public static int d(String msg, Throwable tr) {
        if (IS_DEBUG) {
            return Log.d(getClassName(), msg, tr);
        }
        return 0;
    }

    @SuppressWarnings("unused")
    public static int i(String msg) {
        if (IS_DEBUG) {
            return Log.i(getClassName(), msg);
        }
        return 0;
    }

    @SuppressWarnings("unused")
    public static int i(String msg, Throwable tr) {
        if (IS_DEBUG) {
            return Log.i(getClassName(), msg, tr);
        }
        return 0;
    }

    public static int i(int value) {
        return i(String.valueOf(value));
    }

    public static int i(long value) {
        return i(String.valueOf(value));
    }

    public static int i(float value) {
        return i(String.valueOf(value));
    }

    @SuppressWarnings("unused")
    public static int w(String msg) {
        if (IS_DEBUG) {
            return Log.w(getClassName(), msg);
        }
        return 0;
    }

    @SuppressWarnings("unused")
    public static int w(String msg, Throwable tr) {
        if (IS_DEBUG) {
            return Log.w(getClassName(), msg, tr);
        }
        return 0;
    }

    @SuppressWarnings("unused")
    public static int e(String msg) {
        if (IS_DEBUG) {
            return Log.e(getClassName(), msg);
        }
        return 0;
    }

    @SuppressWarnings("unused")
    public static int e(String msg, Throwable tr) {
        if (IS_DEBUG) {
            return Log.e(getClassName(), msg, tr);
        }
        return 0;
    }

    /**
     * @return 当前的类名(simpleName)
     */
    private static String getClassName() {
        String result;
        StackTraceElement thisMethodStack = (new Exception()).getStackTrace()[2];
        result = thisMethodStack.getClassName();
        int lastIndex = result.lastIndexOf(".");
        result = result.substring(lastIndex + 1, result.length());
        return result;
    }
}